﻿using FinalPointSet.Model.Model.MockData;
using FinalPointSet.ViewModel.Page.MainView;
using System.Windows.Controls;

namespace FinalPointSet.View.Page.MainView
{
    /// <summary>
    /// MockDataPage.xaml 的交互逻辑
    /// </summary>
    public partial class MockDataPage : System.Windows.Controls.Page
    {
        public MockDataPage()
        {
            InitializeComponent();
        }

        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (sender == null)
                return;
            ComboBox comboBox = (ComboBox)sender;
            MockField mockField = (MockField)comboBox.DataContext;

            MockRule? newCustomScript = null;
            MockRule? oldCustomScript = null;
            if (e.AddedItems != null && e.AddedItems.Count > 0)
            {
                newCustomScript = e.AddedItems[0] as MockRule;
            };
            if (e.RemovedItems != null && e.RemovedItems.Count > 0)
            {
                oldCustomScript = e.RemovedItems[0] as MockRule;
            };
            MockDataPageViewModel viewModel = (MockDataPageViewModel)DataContext;
            viewModel.OnComboboxSelectionChange(mockField.Index, newCustomScript, oldCustomScript);
        }

        private void ParamTemplateComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (sender == null) return;
            ComboBox cmb = (ComboBox)sender;
            MockField mockField = (MockField)cmb.DataContext;
            if (mockField == null) return;

            MockParamTemplate? newMPT = null;
            MockParamTemplate? oldMPT = null;
            if (e.AddedItems != null && e.AddedItems.Count > 0)
            {
                newMPT = e.AddedItems[0] as MockParamTemplate;
            };
            if (e.RemovedItems != null && e.RemovedItems.Count > 0)
            {
                oldMPT = e.RemovedItems[0] as MockParamTemplate;
            };
            MockDataPageViewModel viewModel = (MockDataPageViewModel)DataContext;
            viewModel.OnParamTemplateComboboxSelectionChange(mockField.Index, newMPT, oldMPT);
        }
    }
}
